//
//  WBHomeViewController.swift
//  weibo
//
//  Created by GOD on 16/9/2.
//  Copyright © 2016年 磊王. All rights reserved.
//

import UIKit
//定义全局常量,私有，否则哪里都会访问到
private let cellID = "cellID"

class WBHomeViewController: WBBaseViewController {
    private lazy var statusList = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
       
    }
    @objc private func showFriends(){
        print(#function)
        let vc = WBDemoViewController()
        vc.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(vc, animated: true)
        
    }
    
    override func loadData() {
        //模拟延迟加载数据
        print("准备加载数据")
        //延时两秒加载数据
        let time = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * (NSEC_PER_SEC)) )
        dispatch_after(time, dispatch_get_main_queue()) {
            
            for i in 0..<15 {
                if self.isPullUp{
                    self.statusList.append("上拉\(i)")
                
                }else{
                //将数据插入数组的顶部
                self.statusList.insert(i.description, atIndex: 0)
                }
            }
            print("刷新表格")
            //恢复上拉刷新标志
            self.isPullUp = false
            self.refreshControl?.endRefreshing()
            self.tableView?.reloadData()
            
        }
        
        
    }

    
}
//MARK: - 加载数据源
extension WBHomeViewController{
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return statusList.count
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath)
        cell.textLabel?.text = statusList[indexPath.row]
        
        return cell
    }


}
//MARK: - 设置界面
extension WBHomeViewController{
    override func setUI() {
        super.setUI()
        //navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "好友", style:.Plain, target: self, action: #selector(showFriends))
        
//        let btn = UIButton.cz_textButton("好友", fontSize: 16, normalColor: UIColor.grayColor(), highlightedColor: UIColor.orangeColor())
//        btn.addTarget(self, action: #selector(showFriends), forControlEvents: .TouchUpInside)
        //navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
        tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellID)
        
        
    }

}
